// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   GetImg.java

package include.ajax;

import include.nseer_db.nseer_db;
import java.sql.ResultSet;
import java.util.StringTokenizer;

public class GetImg
{

	private nseer_db db;
	private String pic;

	public GetImg()
	{
	}

	public String get(String dbname, String tname, String module, String sub, String subvalue, String href)
	{
		try
		{
			db = new nseer_db(dbname);
			String first_kind_name = "";
			String second_kind_name = "";
			if (tname.equals("document_first"))
			{
				String sql = (new StringBuilder("select picture from ")).append(tname).append(" where main_kind_name='").append(module).append("' and ").append(sub).append("='").append(subvalue).append("'").toString();
				ResultSet rs = db.executeQuery(sql);
				if (rs.next())
					pic = rs.getString("picture");
			} else
			if (tname.equals("document_second") && href.indexOf("?") == -1)
			{
				for (StringTokenizer tokenTO = new StringTokenizer(href, "/"); tokenTO.hasMoreTokens();)
				{
					String main = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
					String s = tokenTO.nextToken();
				}

				String sql = (new StringBuilder("select picture from ")).append(tname).append(" where main_kind_name='").append(module).append("' and first_kind_name='").append(first_kind_name).append("' and ").append(sub).append("='").append(subvalue).append("'").toString();
				ResultSet rs = db.executeQuery(sql);
				if (rs.next())
					pic = rs.getString("picture");
			} else
			if (tname.equals("document_second") && href.indexOf("?") != -1)
			{
				href = href.substring(href.indexOf("?") + 5);
				for (StringTokenizer tokenTO = new StringTokenizer(href, "/"); tokenTO.hasMoreTokens();)
				{
					String main = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
					second_kind_name = tokenTO.nextToken();
				}

				String sql = (new StringBuilder("select picture from ")).append(tname).append(" where main_kind_name='").append(module).append("' and first_kind_name='").append(first_kind_name).append("' and ").append(sub).append("='").append(subvalue).append("'").toString();
				ResultSet rs = db.executeQuery(sql);
				if (rs.next())
					pic = rs.getString("picture");
			} else
			if (tname.equals("document_third"))
			{
				for (StringTokenizer tokenTO = new StringTokenizer(href, "/"); tokenTO.hasMoreTokens();)
				{
					String main = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
					second_kind_name = tokenTO.nextToken();
					String s1 = tokenTO.nextToken();
				}

				String sql = (new StringBuilder("select picture from ")).append(tname).append(" where main_kind_name='").append(module).append("' and first_kind_name='").append(first_kind_name).append("' and second_kind_name='").append(second_kind_name).append("' and ").append(sub).append("='").append(subvalue).append("'").toString();
				ResultSet rs = db.executeQuery(sql);
				if (rs.next())
					pic = rs.getString("picture");
			}
			db.close();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return pic;
	}
}
